<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>抓取配置</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
   <c:out value="version"></c:out>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
     <link rel="apple-touch-icon-precomposed" sizes="144x144" href="../bootstrap/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="../bootstrap/ico/apple-touch-icon-114-precomposed.png">
      <link rel="apple-touch-icon-precomposed" sizes="72x72" href="../bootstrap/ico/apple-touch-icon-72-precomposed.png">
                    <link rel="apple-touch-icon-precomposed" href="../bootstrap/ico/apple-touch-icon-57-precomposed.png">
                    
     <style type="text/css">
     
     body {
     	font-family: "Microsoft YaHei"
     }
     table {
     	font-family: "Microsoft YaHei"
     }
     button {
     	font-family: "Microsoft YaHei"
     }
     .table-bordered {
				-webkit-box-shadow: 0 1px 1px #ccc;
				-moz-box-shadow: 0 1px 1px #ccc;
				box-shadow: 0 1px 1px #ccc;
			}
	 
     	.table-bordered th {
				background-color: #dce9f9;
				background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));
				background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);
				background-image: -moz-linear-gradient(top, #ebf3fc, #dce9f9);
				background-image: -ms-linear-gradient(top, #ebf3fc, #dce9f9);
				background-image: -o-linear-gradient(top, #ebf3fc, #dce9f9);
				background-image: linear-gradient(top, #ebf3fc, #dce9f9);
				filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#ebf3fc, endColorstr=#dce9f9);
				-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#ebf3fc, endColorstr=#dce9f9)";
			}
			.zebra th {				
				background-color: #eee;
				background-image: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#eee));
				background-image: -webkit-linear-gradient(top, #f5f5f5, #eee);
				background-image: -moz-linear-gradient(top, #f5f5f5, #eee);
				background-image: -ms-linear-gradient(top, #f5f5f5, #eee);
				background-image: -o-linear-gradient(top, #f5f5f5, #eee);
				background-image: linear-gradient(top, #f5f5f5, #eee);
				filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#f5f5f5, endColorstr=#eeeeee);
				-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#f5f5f5, endColorstr=#eeeeee)";
			}
			
			body {filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, EndColorStr='#ff00ff', StartColorStr='#00ffff');}
     </style>
  </head>
  <body  data-spy="scroll" data-target=".navbar">
    
	
	<div class="navbar  navbar-fixed-top navbar-static-top ">
	  <div class="navbar-inner">
	  <div class="container">
	  		 <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
		    <a class="brand" href="/confList.html" style="color :#0069d6;font-weight:bold">&nbsp;抓取配置</a>
		    <div class="container">
			    <ul class="nav">
			    <%
			    	
			    %>
			    <c:forEach items="${confs}" var="c">
			    	 <li <c:if test="${c[0]}">class="active"</c:if> id = "nav_li_${c[0]}"><a href="?actionName=${c[0] }" >${ c[1]}</a></li>
			    </c:forEach>
			     
			      
			    </ul>
			 </div>
	    </div>
	  </div>
	</div>

	<div style="height:50px"></div>
	<div class="container">
	  
	  	<form action="../../" id = "confForm" method="post">
	  	
		<table class="table  table-striped table-bordered table-hover " >
		
			<thead>
				<tr>
					<th style="width:40%">描述</th>
					<th style="width:60%">值</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach var="c"  items="${options}"> 
					<tr <c:if test="${c.defaultType eq 'hidden' }">style="display:none"</c:if>>
						<td>[${c.name}]${c.describe}</td>
						<td>
						
							<c:set var="flag"  value="init"></c:set>
							<c:if test="${'select' eq c.defaultType }" >
								
								<select name="${c.name }">
									<c:forEach  var="subC"  items="${c.defaultValue}" >
										<option name="${ subC}" ${isReadonly}}> ${subC }</option>
									</c:forEach>
								</select>
								<c:set var="flag"  value=" 1"></c:set>
							
							</c:if>
							<c:if test="${'text' eq c.defaultType }">
							         <textarea style="width: 500px" name= "${c.name}"  id= "${c.name}"  rows="10" ${isReadonly}>${ c.defaultValue[0]}</textarea>
							         <c:set var="flag"  value=" 1"></c:set>
							 </c:if>
 							
							
							
							<c:if test="${'hidden' eq c.defaultType }">
							         <input style="width: 500px" type="hidden" name= "${c.name}"  id= "${c.name}"  value="${ c.defaultValue[0]}" ${isReadonly}>
							         <c:set var="flag"  value=" 1"></c:set>
							  </c:if>
							   <c:if test="${flag eq 'init' }">
							         <input style="width: 500px" name= "${c.name}"  id= "${c.name}"  value="${ c.defaultValue[0]}" ${isReadonly}>
							   </c:if>
							   ${c.defaultType}
							</td>
						
					</tr>
				</c:forEach>
				<tr >
				    <td>
				        数据源类型
				    </td>
				    <td>
				        <select name="confType"  id = "confType" style="width:100px">
	                         
	                         <c:forEach items="${confType}"  var="c">
	                                <option value="${c[0] }" <c:if test="${ c[0] eq selectedConfType }">selected</c:if>>${c[1] }</option>
	                         </c:forEach>
                        </select>
				    </td>
				</tr>
				<tr >
				
					
					<td colspan="2">
						<input type="hidden" name = "actionName"  value="${actionName}"/>
						
						<div class="row" style="text-align: center">
								<div class="span2 offset1"><button type="button"  class=" btn btn-primary btn-large btn-block"  onclick="submitForm('testConf.html?testType=topList')">测试首页抓取</button></div>
								<div class="span2"><button type="button"  class=" btn btn-primary btn-large btn-block"   onclick="submitForm('testConf.html?testType=testOne&id=0')">测试第一条正文抓取</button></div>
						  		<div class="span2"><button type="button"  class=" btn btn-primary btn-large btn-block"  onclick="submitForm('testConf.html?testType=all')">测试整体流程</button></div>
							
								<div class="span2 "><button type="button "   class="btn btn-large btn-block btn-danger"   onclick="submitForm('addConf.html')" ${isDisabled}>提交配置</button></div>
								<div class="span2"><button type="button "   class="btn btn-large btn-block btn-danger"   onclick="submitForm('addConf.html?update=true')" ${isDisabled}>更新配置</button></div>
							
						</div>
						
						
					</td>
				</tr>
			</tbody>
		</table>
		</form>
		<c:if test="${not empty testType}">
			<h4>抓取结果</h4>
			<a href=""  name="result"></a>
			<table class="table  table-striped table-bordered table-hover " >
			
			<thead>
				<tr>
					<th>标题</th>
					<th>tag</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach var="c"  items="${news}"  varStatus="v"> 
					<tr>
						<td><a href="${c.url }"  target="_blank">${c.title}</a></td>
						<td>${c.user_tag}</td>
						<td>
							<c:if test="${not empty c.body }">
								<a href = "./show.html?id=${v.index}&actionName=${actionName}&formatContent=${formatContent}"  class="btn btn-primary"  target="_blank"/>查看全文</a>
							</c:if>
							
								<button  onclick="submitForm('testConf.html?testType=testOne&id=${v.index}#result');return false;" class="btn btn-info" />测试</button>
							
							
						</td>
						
					</tr>
				</c:forEach>
			</tbody>
		</table>
		</c:if>
		
		<jsp:include page="common/common_foot.jsp"></jsp:include>

		
	</div>


<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript">
	
		function showNav(id){
			
			$(".nav li").each(function (i, n){
				
				
				var n = $(n);
				n.removeClass("active");
				if(i == id){
					n.addClass("active");
				}
			});
			
		}
		$("#nav_li_${actionName}").addClass("active");
		function submitForm(action){
			
			$("#confForm").attr("action", action).submit();
		}
		$(document).ready(function(){
			if("${error}" != "" ){	
				try {
					alert("${error}");
				} catch (e) {
				}
			}
			
			//恢复参数
			<c:if test="${not empty params }">
				var params = [];
				<c:forEach  var="c"  items="${params}"  varStatus="v">
					params["${v.index}"]= ["${c[0]}", "${c[1]}"];
				</c:forEach>
			for(id  in params){
				try {
					var cur = params[id];
					$("#" + cur[0]).val(cur[1].replace(/\{n\}/g, "\n"));
				}catch(e){
				}
			}
			</c:if>
		});
	</script>
   
   
  </body>
</html>